﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using entidades;
using Servicos;
using Google.Api.Maps.Service.Geocoding;
using Google.Api.Maps.Service;

namespace ASPNETUI
{
    public partial class Default : System.Web.UI.Page
    {
        private String geocode;
        private const String rj = "Rio de Janeiro - RJ, Brazil";

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void endereco_TextChanged(object sender, EventArgs e)
        {

        }

        protected void Button_Salvar(object sender, EventArgs e)
        {
            //String endereçoformatado = endereco.Text + " - " + "Rio de Janeiro" + " - " + "RJ" + " - " + " Brasil";            
            
            geocode = GerenciadorLocalizacao.ObterGeocode(endereco.Text);

            if (geocode != null)
            {
                if(geocode.Contains("Rio de Janeiro") && !geocode.Equals(rj))
                {
                    //resultsTreeView.ItemsSource = response.Results.ToTree();                
                    Blitz Blitz = new Blitz(0, "teste", 0, "Rio de Janeiro", "Rio de Janeiro", DateTime.Now, "000000", geocode);

                    //teste com LINQ to SQL
                    BlitzServicoLINQ BlitsServico = new BlitzServicoLINQ();
                    BlitsServico.create(Blitz);
                    BlitsServico.ObterBlitzs();                
                }                
            }            
        }
    }
}